/**
 */
package fUML.Semantics.Activities.ExtraStructuredActivities.impl;

import fUML.Semantics.Actions.BasicActions.OutputPinActivation;

import fUML.Semantics.Activities.ExtraStructuredActivities.ExpansionActivationGroup;
import fUML.Semantics.Activities.ExtraStructuredActivities.ExpansionRegionActivation;
import fUML.Semantics.Activities.ExtraStructuredActivities.ExtraStructuredActivitiesPackage;

import fUML.Semantics.Activities.IntermediateActivities.impl.ActivityNodeActivationGroupImpl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.EcoreUtil;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Expansion Activation Group</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link fUML.Semantics.Activities.ExtraStructuredActivities.impl.ExpansionActivationGroupImpl#getRegionInputs <em>Region Inputs</em>}</li>
 *   <li>{@link fUML.Semantics.Activities.ExtraStructuredActivities.impl.ExpansionActivationGroupImpl#getGroupInputs <em>Group Inputs</em>}</li>
 *   <li>{@link fUML.Semantics.Activities.ExtraStructuredActivities.impl.ExpansionActivationGroupImpl#getRegionActivation <em>Region Activation</em>}</li>
 *   <li>{@link fUML.Semantics.Activities.ExtraStructuredActivities.impl.ExpansionActivationGroupImpl#getGroupOutputs <em>Group Outputs</em>}</li>
 *   <li>{@link fUML.Semantics.Activities.ExtraStructuredActivities.impl.ExpansionActivationGroupImpl#getIndex <em>Index</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ExpansionActivationGroupImpl extends ActivityNodeActivationGroupImpl implements ExpansionActivationGroup {
	/**
	 * The cached value of the '{@link #getRegionInputs() <em>Region Inputs</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRegionInputs()
	 * @generated
	 * @ordered
	 */
	protected EList<OutputPinActivation> regionInputs;

	/**
	 * The cached value of the '{@link #getGroupInputs() <em>Group Inputs</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGroupInputs()
	 * @generated
	 * @ordered
	 */
	protected EList<OutputPinActivation> groupInputs;

	/**
	 * The cached value of the '{@link #getGroupOutputs() <em>Group Outputs</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGroupOutputs()
	 * @generated
	 * @ordered
	 */
	protected EList<OutputPinActivation> groupOutputs;

	/**
	 * The default value of the '{@link #getIndex() <em>Index</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIndex()
	 * @generated
	 * @ordered
	 */
	protected static final int INDEX_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getIndex() <em>Index</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIndex()
	 * @generated
	 * @ordered
	 */
	protected int index = INDEX_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ExpansionActivationGroupImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ExtraStructuredActivitiesPackage.Literals.EXPANSION_ACTIVATION_GROUP;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<OutputPinActivation> getRegionInputs() {
		if (regionInputs == null) {
			regionInputs = new EObjectResolvingEList<OutputPinActivation>(OutputPinActivation.class, this, ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__REGION_INPUTS);
		}
		return regionInputs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<OutputPinActivation> getGroupInputs() {
		if (groupInputs == null) {
			groupInputs = new EObjectResolvingEList<OutputPinActivation>(OutputPinActivation.class, this, ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__GROUP_INPUTS);
		}
		return groupInputs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ExpansionRegionActivation getRegionActivation() {
		if (eContainerFeatureID() != ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__REGION_ACTIVATION) return null;
		return (ExpansionRegionActivation)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetRegionActivation(ExpansionRegionActivation newRegionActivation, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newRegionActivation, ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__REGION_ACTIVATION, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setRegionActivation(ExpansionRegionActivation newRegionActivation) {
		if (newRegionActivation != eInternalContainer() || (eContainerFeatureID() != ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__REGION_ACTIVATION && newRegionActivation != null)) {
			if (EcoreUtil.isAncestor(this, newRegionActivation))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newRegionActivation != null)
				msgs = ((InternalEObject)newRegionActivation).eInverseAdd(this, ExtraStructuredActivitiesPackage.EXPANSION_REGION_ACTIVATION__ACTIVATION_GROUPS, ExpansionRegionActivation.class, msgs);
			msgs = basicSetRegionActivation(newRegionActivation, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__REGION_ACTIVATION, newRegionActivation, newRegionActivation));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<OutputPinActivation> getGroupOutputs() {
		if (groupOutputs == null) {
			groupOutputs = new EObjectResolvingEList<OutputPinActivation>(OutputPinActivation.class, this, ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__GROUP_OUTPUTS);
		}
		return groupOutputs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getIndex() {
		return index;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setIndex(int newIndex) {
		int oldIndex = index;
		index = newIndex;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__INDEX, oldIndex, index));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__REGION_ACTIVATION:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetRegionActivation((ExpansionRegionActivation)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__REGION_ACTIVATION:
				return basicSetRegionActivation(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__REGION_ACTIVATION:
				return eInternalContainer().eInverseRemove(this, ExtraStructuredActivitiesPackage.EXPANSION_REGION_ACTIVATION__ACTIVATION_GROUPS, ExpansionRegionActivation.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__REGION_INPUTS:
				return getRegionInputs();
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__GROUP_INPUTS:
				return getGroupInputs();
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__REGION_ACTIVATION:
				return getRegionActivation();
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__GROUP_OUTPUTS:
				return getGroupOutputs();
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__INDEX:
				return getIndex();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__REGION_INPUTS:
				getRegionInputs().clear();
				getRegionInputs().addAll((Collection<? extends OutputPinActivation>)newValue);
				return;
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__GROUP_INPUTS:
				getGroupInputs().clear();
				getGroupInputs().addAll((Collection<? extends OutputPinActivation>)newValue);
				return;
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__REGION_ACTIVATION:
				setRegionActivation((ExpansionRegionActivation)newValue);
				return;
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__GROUP_OUTPUTS:
				getGroupOutputs().clear();
				getGroupOutputs().addAll((Collection<? extends OutputPinActivation>)newValue);
				return;
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__INDEX:
				setIndex((Integer)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__REGION_INPUTS:
				getRegionInputs().clear();
				return;
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__GROUP_INPUTS:
				getGroupInputs().clear();
				return;
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__REGION_ACTIVATION:
				setRegionActivation((ExpansionRegionActivation)null);
				return;
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__GROUP_OUTPUTS:
				getGroupOutputs().clear();
				return;
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__INDEX:
				setIndex(INDEX_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__REGION_INPUTS:
				return regionInputs != null && !regionInputs.isEmpty();
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__GROUP_INPUTS:
				return groupInputs != null && !groupInputs.isEmpty();
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__REGION_ACTIVATION:
				return getRegionActivation() != null;
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__GROUP_OUTPUTS:
				return groupOutputs != null && !groupOutputs.isEmpty();
			case ExtraStructuredActivitiesPackage.EXPANSION_ACTIVATION_GROUP__INDEX:
				return index != INDEX_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (index: ");
		result.append(index);
		result.append(')');
		return result.toString();
	}

} //ExpansionActivationGroupImpl
